#ifndef SQLITEDATABASE_H
#define SQLITEDATABASE_H

#include <QObject>
#include <QSqlDatabase>
#include <QJsonObject>
#include <QJsonArray>
#include <QMutex>
#include <QSqlRecord>
#include <QCoreApplication>
#include <QDir>
class SQLiteDatabase : public QObject {
    Q_OBJECT

public:
    static SQLiteDatabase* getInstance();
    QSqlDatabase getConnection();
    void create(const QString& table, const QJsonObject& data);
    QJsonArray read(const QString& table, const QString& condition = "");
    void update(const QString& table, const QJsonObject& data, const QString& condition);
    void deleteRecord(const QString& table, const QString& condition);
    bool deleteRecords(const QString& table, const QString& condition);
private:
    explicit SQLiteDatabase(QObject* parent = nullptr);
    ~SQLiteDatabase();
    SQLiteDatabase(const SQLiteDatabase&) = delete;
    SQLiteDatabase& operator=(const SQLiteDatabase&) = delete;
    static SQLiteDatabase* instance;
    static QMutex mutex;
    QSqlDatabase db;

    void executeQuery(const QString& query);
};

#endif // SQLITEDATABASE_H
